<!DOCTYPE html>
<html lang="en">
[#escape x as x?html]
<head>
    <meta charset="utf-8">
	<title>商品搜索-${setting.name}</title>
	[#include "/common/include.ftl"/]
	[#import "common/pagination.ftl" as p/]
	<link type="text/css" rel="stylesheet" href="${base}/resource/css/list.css">
	<script type="text/javascript" src="${base}/resource/js/list.js"></script>
	<script type="text/javascript">
		$(function() {
            /**
             * 商品收藏
             */
            $(".collect").click(function () {
                var _this = $(this);
                ajax({
                    url: base + "/member/addFavorite.jhtml",
                    data: {goodsIds: $(this).attr("product-id")},
                    showError: true,
                    cache: false,
                    success: function(data) {
                        oDialog.prompt("商品收藏成功!");
                        _this.addClass("collected");
                    }
                });
            });
            /**
             * 加入购物车
             */
            $(".add-cart").click(function() {
				var _this = $(this);
				addCartSlide(_this, 1, _this.attr("goodsId"), _this.attr("imgUrl"));
			});

			$("a.click-to-search").click(function(){
				var idMark = $(this).closest("ul").attr('value');
				if($("#"+idMark).val() != $(this).attr('value')){
					$("#"+idMark).val($(this).attr('value'));
                }else{
                    $("#"+idMark).val('');
				}
				$("#goodsForm").submit();
			});

            /**
             * 初始化选中显示状态
             */
            initSelected();
		});

		function initSelected(){
			var arr = [];
			arr.push({"name":"categoryCode", desc:"分类", "value":"${categoryCode}", "filter":"${categoryCode}"});
			arr.push({"name":"manufacturer", desc:"生产厂家", "value":"${manufacturer}", "filter":"${manufacturer}" });
			arr.push({"name":"drugForm", desc:"剂型", "value":"${drugForm}", "filter":"${drugForm}" });
			arr.push({"name":"prescribeType", desc:"处方类型", "value":"${prescribeType}", "filter":"${message('PrescribeType.'+prescribeType)}" });
			arr.push({"name":"medicalInsuranceType", desc:"医保类型", "value":"${medicalInsuranceType}", "filter":"${message('MedicalInsuranceType.'+medicalInsuranceType)}" });
			arr.push({"name":"brand", desc:"品牌",  "value":"${brandName}", "filter":"${brandName}" });

            $.each(arr, function(index, value) {
                if(value.value != ''){
                    //隐藏选中条件
                    $("ul[value="+ value.name+"]").closest("dl").hide();
                    //除分类之外，添加选中状态

                    var  $item = $('<a href="javascript:;"></a>');
                    if(value.name != "categoryCode"){
                        $item.html(value.desc+ ':'+value.filter+'<i></i>');
                    }else{
                        var name = $("a[value='"+value.value+"'] > span").text();
                        $item.html(value.desc+ ':'+name+'<i></i>');
                    }
                    $item.attr('mark', value.name);
                    $item.attr('value', value.value);
                    $(".filter .selected").append($item);


                    $(".filter .selected a").click(function(){
                        var idMark = $(this).attr('mark');
                        if($("#"+idMark).val() != ''){
                            $("#"+idMark).val('');
                        }
                        $("#goodsForm").submit();
                    });
                }
            });
		}
	</script>
</head>
<body class="customer">
	[#include "/common/header.ftl"/]
    <form id="goodsForm" action="${base}/search/${keyword}.jhtml" method="get">
        <input type="hidden" id="categoryCode" name="categoryCode" value="${(categoryCode)!''}"/>
        <input type="hidden" id="manufacturer" name="manufacturer" value="${(manufacturer)!''}"/>
        <input type="hidden" id="drugForm" name="drugForm" value="${(drugForm)!''}"/>
        <input type="hidden" id="prescribeType" name="prescribeType" value="${(prescribeType)!''}"/>
        <input type="hidden" id="medicalInsuranceType" name="medicalInsuranceType" value="${(medicalInsuranceType)!''}"/>
        <input type="hidden" id="goodsSort" name="goodsSort" value="${(goodsSort)!'TopDesc'}"/>
		<input type="hidden" id="brand" name="brandName" value="${brandName}"/>
    </form>
    <div class="body w">
        <div class="list-crumb">

            <ul class="filter fl">
				<li class="home"><a href="${base}/index.jhtml"><i></i><span>首页</span></a></li>
				<li class="left-ico"></li>
				<li><a><span>搜索</span></a></li>
                <li class="left-ico"></li>
                <li class="selected"></li>
            </ul>
            <div class="goods-total-num fr">共${(pager.totalCount)!'0'}条</div>
            <div class="clear"></div>
        </div>

        <div class="filter-wrap">
		[#if selectorList?? && selectorList?size>0]
			[#list selectorList as selector]
			[#if (selector.result)?? && selector.result?has_content]
			<dl class="[#if !selector_has_next]last[/#if]  [#if selector.mark = "brand"]brand-list[/#if]">
				<dt>${(selector.name)!''}</dt>
				<dd class="f-list">
					<ul class="fl ls s" value="${selector.mark}">
						[#list selector.result as data]
							<li>
								<a value="${data.value}" class="click-to-search" href="javascript:" title="${data.label}" class="w-max">
									<span>
										   [#if selector.mark = "brand"]
                                               <img title="${data.value}" class="lazy"  data-original="[@Pic pic=data.label/]" width="104" height="52"/>
                                           [#elseif selector.mark = "categoryCode"]
                                                ${(data.label)!''}
                                           [#else]
                                                ${(data.label)!''}(${(data.count)!})
                                           [/#if]
									</span>
								</a>
							</li>
						[/#list]
					</ul>
                    <div class="more fr"><a href="javascript:" class="more-button up">更多</a></div>
				</dd>
			</dl>
			[/#if]
			[/#list]
		[/#if]
        </div>
        <div class="main mt10">
            <div class="slide-left fl">
                <div class="left-wrap">
                    <div class="mt">
                        <h2>热卖推荐</h2>
                    </div>
                    <div class="mc">
                        <ul>
						[@b2c_goods_list hasStock=true cateCode=categoryCode count=4 orderBy="views desc"]
							[#list goodsList as bean]
                                <li>
                                    <i class="host"></i>
                                    <div class="img">
                                        <a target="_blank" href="${base}/goods/${bean.id}.jhtml">
                                            <img class="lazy" data-original="[@Pic pic=bean.image_default postfix="164x170"/]" width="164" height="170">
                                        </a>
                                    </div>
                                    <p class="price"><em>￥</em><span>${currency(bean.price,false)}</span></p>
                                    <p class="name"><a href="${base}/goods/${bean.id}.jhtml" target="_blank">[#--<strong>[包邮]</strong>--]<span>${bean.name}&nbsp;${bean.spec}</span></a></p>
                                </li>
							[/#list]
						[/@b2c_goods_list]
                        </ul>
                    </div>
                </div>
            </div>
            <div class="slide-right fr">
                <div id="fixed-search">
                    <div class="search-logo"></div>
                </div>
			[#if pager?? && pager.list?has_content]
                <div class="fliter-tools">
                    <ul class="filter-list fl" value="goodsSort">
					[#if sortList?has_content]
						[#list sortList as sortSelector]
						<li class="[#if sortSelector.isSelected?? && sortSelector.isSelected]select[/#if] ico
							[#if sortSelector.url='PriceDesc']
								down-ico up
							[#elseif sortSelector.url='PriceAsc']
							    down-ico down
							[/#if]
						">
							<a value="${sortSelector.url}" class="click-to-search" href="javascript:;">
								<span>${sortSelector.name}</span><i></i>
							</a>
						</li>
						[/#list]
					[/#if]
                       [#-- <li>
                            <div class="checkbox-wrap">
                                <p>
                                    <label>
                                        <input type="checkbox"><span>医卡通</span>
                                    </label>
                                    <label>
                                        <input type="checkbox"><span>包邮</span>
                                    </label>
                                    <label>
                                        <input type="checkbox"><span>促销</span>
                                    </label>
                                </p>
                            </div>
                        </li>--]
                    </ul>
                    <div class="t-pages fr">
                        <div class="page-nums"><strong>${(pager.pageNumber)!1}</strong><span>/${(pager.pageCount)!1}</span></div>
                        <div class="page-btns">
                            <a href="javascript:[#if pager.pageNumber>1]page_search_go2(${pager.pageNumber-1})[/#if];" class="prev [#if pager.pageNumber = 1]disabled[/#if]"></a>
                            <a href="javascript:[#if pager.pageNumber<pager.pageCount]page_search_go2(${pager.pageNumber+1})[/#if];" class="next [#if pager.pageNumber = pager.pageCount]disabled[/#if]"></a>
                        </div>
                    </div>
                </div>
			[/#if]
                <div class="clear"></div>
			[#if pager?? && pager.list?has_content]
                <ul class="product-list">
					[#list pager.list as goods]
                        <li class="product-item">
                            <div class="img">
                                <a href="${base}/goods/${goods.id}.jhtml" target="_blank">
                                    <img class="lazy" alt="${(goods.tip)!goods.name}" title="${(goods.tip)!goods.name}" data-original="[@Pic pic=goods.image_default postfix='200x200'/]" width="200" height="200">
                                </a>
                            </div>
                            <p class="price"><span>￥</span><strong>${currency(goods.price,false)}</strong></p>
                            <div class="name">
                            	<a href="${base}/goods/${goods.id}.jhtml">
                                	<p class="title">[#noescape]${goods.highlighter}[/#noescape] ${goods.spec}/${goods.packingUnit}</p>
									<p class="detail">${(goods.tip)!''}</p>
								</a>
							</div>
                            <div class="jl">
                                <p class="fl"><span>该款成交</span><strong> ${(goods.sales)!0}笔</strong></p>
                                <p class="fr"><span>评论</span><strong>${(goods.cmts)!0}</strong></p>
                                <div class="clear"></div>
                            </div>
                            <div class="cz">
                                <a class="add-cart fl" goodsId="${goods.id}" imgUrl="[@Pic pic=goods.image_default postfix=''/]" href="javascript:;">加入购物车</a>
                                <a href="${base}/goods/${goods.id}.jhtml" target="_blank" class="look-info fr">查看详情</a>
                                <div class="clear"></div>
                            </div>
                        </li>
					[/#list]
                    <li class="clear"></li>
                </ul>
                <div class="pager">
					[@p.pager pager = pager url = "${base}${uri}.jhtml"/]
                </div>
			[#else]
                <div class="list-empty"><span class="nf-icon"></span>
                    <div class="nf-content"><span>抱歉，没有找到相关的商品</span>
                    </div>
                </div>
			[/#if]
            </div>
            <div class="clear"></div>
        </div>
    </div>
	[#include "common/footer-slidebar-lazyload.ftl"]
</body>
[/#escape]
</html>